import { defineMock } from "./base";

export default defineMock([
    {
        url: "menus",
        method: ["GET"],
        body: {
            code: 1,
            data: [
                {
                    path: "/system", //路由路径
                    component: "Layout", // 路由组件
                    name: "system", // 路由名称
                    meta: {
                        // 网页元信息
                        title: "系统管理", // 网页名称
                        icon: "menus_system", // 侧边栏icon
                        hidden: false, // 侧边栏是否展开
                        alwaysShow: true, // 是否一直显示
                        params: null, //
                    },
                    children: [
                        // 子路由
                        {
                            path: "userManager",
                            component: "system/userManager/index",
                            name: "userManager",
                            meta: {
                                title: "用户管理",
                                icon: "menus_userManager",
                                hidden: false,
                                keepAlive: true,
                                alwaysShow: false,
                                params: null,
                            },
                        },

                        {
                            path: "roleManager",
                            component: "system/roleManager/index",
                            name: "roleManager",
                            meta: {
                                title: "角色管理",
                                icon: "menus_roleManager",
                                hidden: false,
                                keepAlive: true,
                                alwaysShow: false,
                                params: null,
                            },
                        },
                        {
                            path: "permissionManager",
                            component: "system/permissionManager/index",
                            name: "permissionManager",
                            meta: {
                                title: "权限管理",
                                icon: "menus_permissionManager",
                                hidden: false,
                                keepAlive: true,
                                alwaysShow: false,
                                params: null,
                            },
                        },
                    ],
                },
            ],
            msg: "一切ok",
        },
    },

    // 获取菜单树形列表
    {
        url: "menus",
        method: ["GET"],
        body: {
            code: 1,
            data: [
                {
                    id: 1,
                    parentId: 0,
                    name: "系统管理",
                    type: "CATALOG",
                    routeName: "",
                    routePath: "/system",
                    component: "Layout",
                    sort: 1,
                    visible: 1,
                    icon: "system",
                    redirect: "/system/userManager",
                    perm: null,
                    children: [
                        {
                            id: 2,
                            parentId: 1,
                            name: "用户管理",
                            type: "MENU",
                            routeName: "userManager",
                            routePath: "userManager",
                            component: "system/userManager/index",
                            sort: 1,
                            visible: 1,
                            icon: "",
                            redirect: null,
                            perm: null,
                            children: [
                                {
                                    id: 105,
                                    parentId: 2,
                                    name: "查询",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 0,
                                    visible: 1,
                                    icon: "",
                                    redirect: null,
                                    perm: "sys:user:query",
                                    children: [],
                                },
                                {
                                    id: 31,
                                    parentId: 2,
                                    name: "添加用户",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 1,
                                    visible: 1,
                                    icon: "",
                                    redirect: "",
                                    perm: "sys:user:add",
                                    children: [],
                                },
                                {
                                    id: 32,
                                    parentId: 2,
                                    name: "编辑",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 2,
                                    visible: 1,
                                    icon: "",
                                    redirect: "",
                                    perm: "sys:user:edit",
                                    children: [],
                                },

                                {
                                    id: 88,
                                    parentId: 2,
                                    name: "重置密码",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 4,
                                    visible: 1,
                                    icon: "",
                                    redirect: null,
                                    perm: "sys:user:password:reset",
                                    children: [],
                                },
                                {
                                    id: 106,
                                    parentId: 2,
                                    name: "批量导入",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 5,
                                    visible: 1,
                                    icon: "",
                                    redirect: null,
                                    perm: "sys:user:import",
                                    children: [],
                                },
                                {
                                    id: 107,
                                    parentId: 2,
                                    name: "用户导出",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 6,
                                    visible: 1,
                                    icon: "",
                                    redirect: null,
                                    perm: "sys:user:export",
                                    children: [],
                                },
                            ],
                        },
                        {
                            id: 3,
                            parentId: 1,
                            name: "角色管理",
                            type: "MENU",
                            routeName: "Role",
                            routePath: "role",
                            component: "system/role/index",
                            sort: 2,
                            visible: 1,
                            icon: "role",
                            redirect: null,
                            perm: null,
                            children: [
                                {
                                    id: 70,
                                    parentId: 3,
                                    name: "角色新增",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 1,
                                    visible: 1,
                                    icon: "",
                                    redirect: null,
                                    perm: "sys:role:add",
                                    children: [],
                                },
                                {
                                    id: 71,
                                    parentId: 3,
                                    name: "角色编辑",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 2,
                                    visible: 1,
                                    icon: "",
                                    redirect: null,
                                    perm: "sys:role:edit",
                                    children: [],
                                },
                                {
                                    id: 72,
                                    parentId: 3,
                                    name: "角色删除",
                                    type: "BUTTON",
                                    routeName: null,
                                    routePath: "",
                                    component: null,
                                    sort: 3,
                                    visible: 1,
                                    icon: "",
                                    redirect: null,
                                    perm: "sys:role:delete",
                                    children: [],
                                },
                            ],
                        },
                    ],
                },
            ],
            msg: "一切ok",
        },
    },

    // 新增菜单
    {
        url: "menus/options",
        method: ["GET"],
        body: {
            code: 1,
            data: [
                {
                    value: "1",
                    label: "系统管理",
                    children: [
                        {
                            value: "2",
                            label: "用户管理",
                        },
                        {
                            value: "3",
                            label: "角色管理",
                        },
                        {
                            value: "4",
                            label: "菜单管理",
                        },
                        {
                            value: "5",
                            label: "部门管理",
                        },
                        {
                            value: "6",
                            label: "字典管理",
                        },
                        {
                            value: "135",
                            label: "字典数据",
                        },
                        {
                            value: "117",
                            label: "系统日志",
                        },
                        {
                            value: "120",
                            label: "系统配置",
                        },
                        {
                            value: "126",
                            label: "通知公告",
                        },
                    ],
                },
                {
                    value: "118",
                    label: "系统工具",
                    children: [
                        {
                            value: "119",
                            label: "代码生成",
                        },
                    ],
                },
                {
                    value: "40",
                    label: "接口文档",
                    children: [
                        {
                            value: "41",
                            label: "Apifox",
                        },
                    ],
                },
                {
                    value: "26",
                    label: "平台文档",
                },
                {
                    value: "20",
                    label: "多级菜单",
                    children: [
                        {
                            value: "21",
                            label: "菜单一级",
                            children: [
                                {
                                    value: "22",
                                    label: "菜单二级",
                                    children: [
                                        {
                                            value: "23",
                                            label: "菜单三级-1",
                                        },
                                        {
                                            value: "24",
                                            label: "菜单三级-2",
                                        },
                                    ],
                                },
                            ],
                        },
                    ],
                },
                {
                    value: "36",
                    label: "组件封装",
                    children: [
                        {
                            value: "108",
                            label: "增删改查",
                        },
                        {
                            value: "109",
                            label: "列表选择器",
                        },
                        {
                            value: "37",
                            label: "富文本编辑器",
                        },
                        {
                            value: "38",
                            label: "图片上传",
                        },
                        {
                            value: "39",
                            label: "图标选择器",
                        },
                        {
                            value: "95",
                            label: "字典组件",
                        },
                    ],
                },
                {
                    value: "110",
                    label: "路由参数",
                    children: [
                        {
                            value: "111",
                            label: "参数(type=1)",
                        },
                        {
                            value: "112",
                            label: "参数(type=2)",
                        },
                    ],
                },
                {
                    value: "89",
                    label: "功能演示",
                    children: [
                        {
                            value: "97",
                            label: "Icons",
                        },
                        {
                            value: "90",
                            label: "Websocket",
                        },
                    ],
                },
            ],
            msg: "111",
        },
    },

    // 获取菜单表单数据
    {
        url: "menus/:id/form",
        method: ["GET"],
        body: ({ params }) => {
            return {
                code: 1,
                data: menuMap[params.id],
                msg: "一切ok",
            };
        },
    },

    // 修改菜单
    {
        url: "menus/:id",
        method: ["PUT"],
        body: {
            code: 1,
            data: [
                {
                    value: "1",
                    label: "系统管理",
                    children: [
                        {
                            value: "2",
                            label: "用户管理",
                        },
                        {
                            value: "3",
                            label: "角色管理",
                        },
                        {
                            value: "4",
                            label: "菜单管理",
                        },
                        {
                            value: "5",
                            label: "部门管理",
                        },
                        {
                            value: "6",
                            label: "字典管理",
                        },
                        {
                            value: "135",
                            label: "字典数据",
                        },
                        {
                            value: "117",
                            label: "系统日志",
                        },
                        {
                            value: "120",
                            label: "系统配置",
                        },
                        {
                            value: "126",
                            label: "通知公告",
                        },
                    ],
                },
                {
                    value: "118",
                    label: "系统工具",
                    children: [
                        {
                            value: "119",
                            label: "代码生成",
                        },
                    ],
                },
                {
                    value: "40",
                    label: "接口文档",
                    children: [
                        {
                            value: "41",
                            label: "Apifox",
                        },
                    ],
                },
                {
                    value: "26",
                    label: "平台文档",
                },
                {
                    value: "20",
                    label: "多级菜单",
                    children: [
                        {
                            value: "21",
                            label: "菜单一级",
                            children: [
                                {
                                    value: "22",
                                    label: "菜单二级",
                                    children: [
                                        {
                                            value: "23",
                                            label: "菜单三级-1",
                                        },
                                        {
                                            value: "24",
                                            label: "菜单三级-2",
                                        },
                                    ],
                                },
                            ],
                        },
                    ],
                },
                {
                    value: "36",
                    label: "组件封装",
                    children: [
                        {
                            value: "108",
                            label: "增删改查",
                        },
                        {
                            value: "109",
                            label: "列表选择器",
                        },
                        {
                            value: "37",
                            label: "富文本编辑器",
                        },
                        {
                            value: "38",
                            label: "图片上传",
                        },
                        {
                            value: "39",
                            label: "图标选择器",
                        },
                        {
                            value: "95",
                            label: "字典组件",
                        },
                    ],
                },
                {
                    value: "110",
                    label: "路由参数",
                    children: [
                        {
                            value: "111",
                            label: "参数(type=1)",
                        },
                        {
                            value: "112",
                            label: "参数(type=2)",
                        },
                    ],
                },
                {
                    value: "89",
                    label: "功能演示",
                    children: [
                        {
                            value: "97",
                            label: "Icons",
                        },
                        {
                            value: "90",
                            label: "Websocket",
                        },
                    ],
                },
            ],
            msg: "111",
        },
    },

    // 删除菜单
    {
        url: "menus/:id",
        method: ["DELETE"],
        body({ params }) {
            return {
                code: 1,
                data: null,
                msg: "删除菜单" + params.id + "成功",
            };
        },
    },
]);

const menuMap: Record<string, any> = {
    1: {
        id: 1,
        parentId: 0,
        name: "系统管理",
        type: "CATALOG",
        routeName: "",
        routePath: "/system",
        component: "Layout",
        perm: null,
        visible: 1,
        sort: 1,
        icon: "system",
        redirect: "/system/user",
        keepAlive: null,
        alwaysShow: null,
        params: null,
    },
    2: {
        id: 2,
        parentId: 1,
        name: "用户管理",
        type: "MENU",
        routeName: "User",
        routePath: "user",
        component: "system/user/index",
        perm: null,
        visible: 1,
        sort: 1,
        icon: "user",
        redirect: null,
        keepAlive: 1,
        alwaysShow: null,
    },
    3: {
        id: 3,
        parentId: 1,
        name: "角色管理",
        type: "MENU",
        routeName: "Role",
        routePath: "role",
        component: "system/role/index",
        perm: null,
        visible: 1,
        sort: 2,
        icon: "role",
        redirect: null,
        keepAlive: 1,
        alwaysShow: null,
    },
    4: {
        id: 4,
        parentId: 1,
        name: "菜单管理",
        type: "MENU",
        routeName: "Menu",
        routePath: "menu",
        component: "system/menu/index",
        perm: null,
        visible: 1,
        sort: 3,
        icon: "menu",
        redirect: null,
        keepAlive: 1,
        alwaysShow: null,
    },
    5: {
        id: 5,
        parentId: 1,
        name: "部门管理",
        type: "MENU",
        routeName: "Dept",
        routePath: "dept",
        component: "system/dept/index",
        perm: null,
        visible: 1,
        sort: 4,
        icon: "tree",
        redirect: null,
        keepAlive: 1,
        alwaysShow: null,
    },
    6: {
        id: 6,
        parentId: 1,
        name: "字典管理",
        type: "MENU",
        routeName: "Dict",
        routePath: "dict",
        component: "system/dict/index",
        perm: null,
        visible: 1,
        sort: 5,
        icon: "dict",
        redirect: null,
        keepAlive: 1,
        alwaysShow: null,
    },
};
